#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "./trimmomatic-0.40.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

if [[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]]; then echo "请输入正确的构建路径"; exit 1; fi
if [[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]]; then echo "请输入正确的安装路径"; exit 1; fi

buildpath=$1
installpath=$2
if [[ "$1" =~ .*/$ ]]; then buildpath=${buildpath%/*}; fi
if [[ "$2" =~ .*/$ ]]; then installpath=${installpath%/*}; fi
[[ "$buildpath" == "$installpath" ]] && echo "构建路径与安装路径需为不同路径" && exit 1
yum -y install  m4 environment-modules systemd-devel  --nogpgcheck
wget -t 0 -c -P $buildpath https://github.com/usadellab/Trimmomatic/archive/refs/heads/main.zip
unzip $buildpath/main.zip -d $buildpath && rm -rf $buildpath/main.zip
cd $buildpath/Trimmomatic-main
sed -i 's/1.5/1.8/g' build.xml
ant
mkdir -p $installpath/trimmomatic-0.40 && cp -r $buildpath/Trimmomatic-main/* $installpath/trimmomatic-0.40/

rm -rf $buildpath/Trimmomatic-main

